﻿using Interop.BugTraqProvider;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace SubVersionOne
{
    
    [ClassInterface(ClassInterfaceType.None), Guid("E0803C52-C543-49a1-BBD8-195F87CB97C9"), ComVisible(true)]
    public class SubVersionOnePlugin : IBugTraqProvider2, IBugTraqProvider
    {
        
        // Methods
        public string CheckCommit(IntPtr hParentWnd, string parameters, string commonUrl, string commonRoot, string[] pathList, string commitMessage)
        {
            return null;
        }

        public string GetCommitMessage(IntPtr hParentWnd, string parameters, string commonRoot, string[] pathList, string originalMessage)
        {
            return this.GetCommitMessage2(hParentWnd, parameters, "", commonRoot, pathList, originalMessage);
        }
        /// <summary>
        /// Gets a message to place into the TortoiseSVN commit message box.
        /// </summary>
        /// <param name="hParentWnd"></param>
        /// <param name="parameters"></param>
        /// <param name="commonUrl"></param>
        /// <param name="commonRoot"></param>
        /// <param name="pathList"></param>
        /// <param name="originalMessage"></param>
        /// <returns></returns>
        public string GetCommitMessage2(IntPtr hParentWnd, string parameters, string commonUrl, string commonRoot, string[] pathList, string originalMessage)
        {
            EventLogger.Init();
            string str = "";


            EventLogger.Info("Init Host");
            FormHost host = new FormHost();
            var result = host.ShowDialog();
            if (result == System.Windows.Forms.DialogResult.OK)
            {
                str = host.Message;
            }
           // host.Dispose();
           // host = null;



            return str;
        }

        public string GetCommitMessage2(IntPtr hParentWnd, string parameters, string commonUrl, string commonRoot, string[] pathList, string originalMessage, string bugId, out string bugIdOut, out string[] revPropNames, out string[] revPropValues)
        {
            bugIdOut = string.Empty;
            revPropNames = new string[0];
            revPropValues = new string[0];
            return this.GetCommitMessage2(hParentWnd, parameters, commonUrl, commonRoot, pathList, originalMessage);
        }

        public string GetLinkText(IntPtr hParentWnd, string parameters)
        {
            return "Choose Work Items";
        }

        public bool HasOptions()
        {
            return false;
        }


        public string OnCommitFinished(IntPtr hParentWnd, string commonRoot, string[] pathList, string logMessage, int revision)
        {
            return string.Empty;
        }

        public string ShowOptionsDialog(IntPtr hParentWnd, string parameters)
        {
            return string.Empty;
        }

        public bool ValidateParameters(IntPtr hParentWnd, string parameters)
        {
            return true;
        }

    }
}
